﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "UObject/Object.h"
#include "StarrySkyWidgetController.generated.h"

class UStarrySkyAttributeSet;
class AStarrySkyPlayerState;
class UStarrySkyAbilitySystemComponent;
class AStarrySkyPlayerController;
class UAttributeSet;
class UAbilitySystemComponent;

//小部件控制器结构体，保存所需要玩家控制器指针，玩家状态指针，能力系统指针，属性集指针，在初始化设置好这些数据
USTRUCT(BlueprintType)
struct FWidgetControllerParams
{
	GENERATED_BODY()
	FWidgetControllerParams(){}
	FWidgetControllerParams(APlayerController* PC, APlayerState* PS, UAbilitySystemComponent* ASC,UAttributeSet* AS)
	: PlayerController(PC), PlayerState(PS), AbilitySystemComponent(ASC), AttributeSet(AS){}

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TObjectPtr<APlayerController> PlayerController;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TObjectPtr<APlayerState> PlayerState;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TObjectPtr<UAttributeSet> AttributeSet;
};

//广播玩家的统计信息如：等级，属性点，技能点
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerStatChangedSignature, int32,NewValue);
/**
 * 
 */
UCLASS()
class STARRYSKY_API UStarrySkyWidgetController : public UObject
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable)
	virtual void SetWidgetControllerParams(const FWidgetControllerParams& WCParams);

	//初始绑定委托
	UFUNCTION(BlueprintCallable)
	virtual void BroadcastInitialValues();

	//实例化小部件控制器时绑定能力系统中属性变化的委托
	virtual void BindCallbacksToDependencies();
protected:
	UPROPERTY(BlueprintReadOnly, Category="WidgetController")
	TObjectPtr<APlayerController> PlayerController;
	
	UPROPERTY(BlueprintReadOnly, Category="WidgetController")
	TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;

	UPROPERTY(BlueprintReadOnly, Category="WidgetController")
	TObjectPtr<UAttributeSet> AttributeSet;

	UPROPERTY(BlueprintReadOnly, Category="WidgetController")
	TObjectPtr<APlayerState> PlayerState;

	UPROPERTY(BlueprintReadOnly, Category="WidgetController")
    TObjectPtr<AStarrySkyPlayerController> StarrySkyPlayerController;
    
    UPROPERTY(BlueprintReadOnly, Category="WidgetController")
    TObjectPtr<UStarrySkyAbilitySystemComponent> StarrySkyAbilitySystemComponent;

    UPROPERTY(BlueprintReadOnly, Category="WidgetController")
    TObjectPtr<UStarrySkyAttributeSet> StarrySkyAttributeSet;

    UPROPERTY(BlueprintReadOnly, Category="WidgetController")
    TObjectPtr<AStarrySkyPlayerState> StarrySkyPlayerState;


	//获取玩家控制器，玩家状态，能力系统，属性集
	AStarrySkyPlayerController* GetStarrySkyPC();
	AStarrySkyPlayerState* GetStarrySkyPS();
	UStarrySkyAbilitySystemComponent* GetStarrySkyASC();
	UStarrySkyAttributeSet* GetStarrySkyAS();
};
